#ifndef __GAMEOBJECTFACTORY_H__
#define __GAMEOBJECTFACTORY_H__

#include <iostream>
#include <map>
#include "BaseCreator.h"
#include "GameObject.h"

class GameObjectFactory{
    public:
        static GameObjectFactory * Instance(){
            if (s_pInstance == nullptr){
                s_pInstance = new GameObjectFactory();
            }
            return s_pInstance;
        }
        bool registerType(std::string typeID, BaseCreator * pCreator){
            std::map<std::string, BaseCreator*>::iterator it=
                m_creators.find(typeID);

            if(it != m_creators.end()){
                delete pCreator;
                return false;
            }

            m_creators[typeID] = pCreator;
            return true;
        }

        GameObject * create(std::string typeID){
            std::map<std::string, BaseCreator*>::iterator it = 
                m_creators.find(typeID);

            if(it == m_creators.end()){
                std::cout << "could not find type: " << typeID << std::endl;
                return nullptr;
            }

            BaseCreator * pCreator = (*it).second;
            return pCreator->createGameObject();
        }

    private:
        std::map<std::string, BaseCreator*> m_creators;

    private:
        GameObjectFactory(){};
        static GameObjectFactory * s_pInstance;
};

typedef GameObjectFactory TheGameObjectFactory;

#endif
